<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="/common/inc::header"/>
<body>
<form class="layui-form">
    <input name="id" id="id" type="hidden"/>
    <br/>
    <div class="layui-form-item">
        <label class="layui-form-label">时间</label>
        <div class="layui-input-inline">
            <input type="text" name="day" id="day" placeholder="请输入天数" autocomplete="off"
                   class="layui-input" lay-verify="required|number">
        </div>
    </div>
    <button class="layui-btn" id="formSubmit" lay-submit="" lay-filter="formSubmit" style="display: none">立即提交</button>
</form>
<script th:replace="/common/inc::incJs"></script>
<script>
    var form = layui.form;
    var successCallback;
    var id = getQueryString("id");
    $("#id").val(id);

    //监听提交
    form.on('submit(formSubmit)', function (data) {
        if (parseInt($("#day").val()) > 365) {
            layer.msg("延长会员时间不得超过365天");
        } else {
            $.post('/backend/security/customer/updateVipDay', {
                id: id,
                days: parseInt($("#day").val())
            }, function (res) {
                if (res.code < 0) {
                    layer.msg(res.message);
                }
                else {
                    layer.msg('操作成功');
                    successCallback && successCallback();
                }
            });
        }
        return false;
    });

    var formSubmit = function (callback) {
        successCallback = callback;
        $("#formSubmit").click();
    };


    $(function () {
        if (id != "") {
            //$("form").loadData('/backend/security/user/getById?id=' + id);
            $.post('/backend/security/user/getById', {id: id}, function (res) {
                if (res.code < 0) {
                    layer.msg(res.message);
                }
                else {
                    $("form").loadData(res.body);
                    $("#account").attr("disabled", "disabled");
                    $("#password2").val(res.body.password);
                }
            });
        }
    })
</script>
</body>
</html>